'use client';

import { useState, useEffect } from 'react';
import { usePathname } from 'next/navigation';

export function useRouteLoading() {
    const [isLoading, setIsLoading] = useState(false);
    const pathname = usePathname();

    useEffect(() => {
        const handleStart = () => {
            setIsLoading(true);
        };

        const handleComplete = () => {
            setIsLoading(false);
        };

        handleStart();
        const timeout = setTimeout(handleComplete, 500); // 最小显示时间

        return () => {
            clearTimeout(timeout);
        };
    }, [pathname]);

    return isLoading;
}
